package traveldream.ejb.sessionBean;

import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import traveldream.ejb.DTO.HotelDTO;
import traveldream.ejb.entities.Hotel;
import traveldream.ejb.interfaces.HotelEditBeanLocal;
import traveldream.ejb.interfaces.NotFindException;

/**
 * Session Bean implementation class HotelEditBean
 */
@Stateless
@LocalBean
public class HotelEditBean implements HotelEditBeanLocal {

	@PersistenceContext
	private EntityManager em;
    /**
     * Default constructor. 
     */
    public HotelEditBean() {
        // TODO Auto-generated constructor stub
    }
    
    public HotelDTO find(int id) throws NotFindException{
    	Hotel h = em.find(Hotel.class, id);
    	try{
    		return h.convertToDTO();
    	}
    	catch(NullPointerException e){
    		throw new NotFindException();
    	}
    }
    
    public void update(HotelDTO hDTO){
    	Hotel h = new Hotel(hDTO);
    	h.setId(hDTO.getId());
    	em.merge(h);
    }

}
